#include "GameState.h"
#include "Objects/Objects.h"
#include "SFML/OpenGL.hpp"
#include "Screens/ScreenBase.h"
#include "Screens/GameScreen.h"
#include "Screens/HomeScreen.h"
#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;


GameState::GameState(sf::RenderTarget &window) : 
	m_window(window),
	m_nextScreen(NULL)
{
	m_font.loadFromFile(fontsPath+"curlywurly.ttf");

	m_currentScreen = new HomeScreen(this);

	
	camera.heightUnits = camera.widthUnits*(float(window.getSize().y)/window.getSize().x);
	float wHalf = camera.widthUnits/2.0f;
	float hHalf = camera.heightUnits/2.0f;
	
	glOrtho(-wHalf, wHalf, 
			-hHalf, hHalf, -100.0, 100.0);

	glViewport(0, 0, window.getSize().x, window.getSize().y);

	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glClearColor(0.4f, 0.9f, 1.0f, 1.0f);

}


GameState::~GameState(){
	
}


void GameState::update(double dt){
	if(m_nextScreen){
		delete m_currentScreen;
		m_currentScreen = m_nextScreen;
		m_currentScreen->init();
		m_nextScreen = 0;
	}

	assert(m_currentScreen);
	m_currentScreen->update(dt);

	
}


void GameState::draw(){
	assert(m_currentScreen);
	m_currentScreen->draw();
}


void GameState::setCurrentScreen(ScreenBase *screen){
	assert(screen);
	m_nextScreen = screen;
}